package com.demo.java.controller;

import com.dangdang.ddframe.rdb.sharding.id.generator.IdGenerator;
import com.demo.java.entity.User;
import com.demo.java.service.UserService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {
	@Autowired
	private UserService userService;
	@Autowired
	private IdGenerator idGenerator;

	@GetMapping("/list")
	public List<User> list() {
		return userService.findByUsers();
	}

	@GetMapping("/getById")
	public User getById(Integer id) {
		return userService.getById(id);
	}

	@GetMapping("/saveUser")
	public int saveUser() {
		User entity = new User();
		entity.setId(idGenerator.generateId().intValue());
		entity.setName("张三");
		entity.setCode("A001");
		return userService.insertUser(entity);
	}

}
